package sis.studentinfo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

public class CourseSession implements Serializable {

	private static final long serialVersionUID = 1L;
	private static int count;
	private String deptment;
	private String number;
	private List<Student> students;
	private Date startDate;
	private int numberOfCredits;
	
	private static void incrementCount() {
		CourseSession.count++;
	}

	private CourseSession(String deptment, String number, Date startDate) {
		this.deptment = deptment;
		this.number = number;
		this.students = new ArrayList<Student>();
		this.startDate = startDate;
	}
	
	public static CourseSession Create(String department, String number,
			Date startDate) {
		CourseSession.incrementCount();
		return new CourseSession(department, number, startDate);
	}
	

	public String getDepartment() {
		return this.deptment;
	}

	public String getNumber() {
		return this.number;
	}

	public int getNumberOfStudents() {
		return this.students.size();
	}

	public void enrool(Student student) {
		student.addCreadits(this.numberOfCredits);
		this.students.add(student);
	}

	public Student get(int i) {
		return this.students.get(i);
	}

	public Date getEndDate() {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(startDate);
		int numberOfDays = 16 * 7 - 3;
		calendar.add(Calendar.DAY_OF_YEAR, numberOfDays);
		return calendar.getTime();
	}

	public List<Student> getAllStudents() {
		return this.students;
	}

	public static Object getCount() {
		return CourseSession.count;
	}

	public static void resetCount() {
		CourseSession.count = 0;
	}

	public void setNumberOfCredits(int credits) {
		this.numberOfCredits = credits;
	}



}
